{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "\n",
    "def get_line(x1, y1, x2, y2):\n",
    "    points = []\n",
    "    issteep = abs(y2-y1) > abs(x2-x1)\n",
    "    if issteep:\n",
    "        x1, y1 = y1, x1\n",
    "        x2, y2 = y2, x2\n",
    "    rev = False\n",
    "    if x1 > x2:\n",
    "        x1, x2 = x2, x1\n",
    "        y1, y2 = y2, y1\n",
    "        rev = True\n",
    "    deltax = x2 - x1\n",
    "    deltay = abs(y2-y1)\n",
    "    error = int(deltax / 2)\n",
    "    y = y1\n",
    "    ystep = None\n",
    "    if y1 < y2:\n",
    "        ystep = 1\n",
    "    else:\n",
    "        ystep = -1\n",
    "    for x in range(x1, x2 + 1):\n",
    "        if issteep:\n",
    "            points.append([y, x])\n",
    "        else:\n",
    "            points.append([x, y])\n",
    "        error -= deltay\n",
    "        if error < 0:\n",
    "            y += ystep\n",
    "            error += deltax\n",
    "    # Reverse the list if the coordinates were reversed\n",
    "    if rev:\n",
    "        points.reverse()\n",
    "    return points"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 0\n",
      "0 0\n",
      "0 0\n",
      "1 0\n",
      "1 0\n",
      "1 1\n",
      "1 1\n"
     ]
    }
   ],
   "source": [
    "points = get_line(1, 2, 7, 4)\n",
    "for x, y in points:\n",
    "    print(x//4, y//4)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "0600588c3b5f4418cbe7b5ebc6825b479f3bc010269d8b60d75058cdd010adfe"
  },
  "kernelspec": {
   "display_name": "Python 3.7.9 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
